
<?php
	header("Content-type:text/html;charset=utf-8");
	require_once(dirname(__FILE__).'/'."../../basic/Model.php");
	class ManagerModel extends Model{
		//private $conn;

		function __construct(){
			parent::__construct();
		}
		
		function staff_add($data){
			$pass='123';
			$time=time();
			$times=date('y-m-d h:i:s',time());
			$staff = array(
  				'username' => trim($_POST['username']),
  				'pass'=>$pass,
				'name' => trim($_POST['name']),  
				'sex' => $_POST['sex'],
				'did'=>$_POST['did'],
				'Birth' => $_POST['Birth'],
				'home' => $_POST['home'],
				'idcard' => $_POST['idcard'],
				'createtime' => $times,
				'state' => $_POST['state'],
  			);
			// $sql="insert into users values(null,'$user[uname]','$user[password]','$user[gender]','$user[birthdate]','$user[hobby]','$user[degree]','$user[intro]','$user[pic]')";
			// 	echo $sql;

			$keys=implode(',', array_keys($staff));
			$values=implode("','",array_values($staff));
			$sql="insert into employees ({$keys})values('{$values}')";
			$result=$this->conn->query($sql);
			return $result;
		}	

		function staff_edit($id){
			$sql = "select * from employees where id={$id}";
			$row=$this->conn->query($sql);	
			return $row;
		}	

		function staff_update($data){
			$id = $_POST['id'];
  			$staff = array(
  				'id'=>$id,
				'name' => trim($_POST['name']),
				'did'=>$_POST['did'] , 
				'sex' => $_POST['sex'],
				'Birth' => $_POST['Birth'],
				'home' => $_POST['home'],
				'idcard' => $_POST['idcard'],
				'createtime' => $_POST['createtime'],
				'state' => $_POST['state'],
  			);
			//$result=$this->conn->query($sql);
			$result =$this->conn->update('employees',$staff,'id='.$id);
			return $result;
		}

		function staff_delete($id){

			 $sql = "delete from employees where id={$id}";
			 $result = $this->conn->query($sql) or die('删除失败！'.mysql_error());

		}

		function Dostaff_search(){
			$name = $_POST['name'];
          $sql="select * from  employees where name like '%$name%'";
          $data=$this->conn->query($sql);
          return $data;
        // $data = new Model();
        // $result=$data->conn->query($sql);
		}

		function pending1(){
			$sql="select * from works where approval=''";
			$data=$this->conn->query($sql);
			return $data;	
		}
		function pending2(){

			$sql2="select * from works where approval!=''";
			$pdata=$this->conn->query($sql2);	
			return $pdata;	
		}

		function staff_Aedit($id){
			$approval='覃冠雄';
			$time=time();
			$times=date('y-m-d h:i:s',time());
			$sql = "select * from works where id={$id}";
			$row=$this->conn->query($sql);	
	
			$staff = array(

				'approval' => $approval,
				'wtime'=>$times		
  			);
			//$result=$this->conn->query($sql);
			$this->conn->update('works',$staff,'id='.$id);
			$staff2=array(
				'state'=>$row[0]['type']
				);
			$this->conn->update('employees',$staff2,'id='.$id);
			//include "manager/staff_Aedit.php";
		}

		function staff_Dedit($id){
			$state='1';
			$staff = array(
				'state'=>$state	
  			);	
			$this->conn->update('employees',$staff,'id='.$id);

			 $sql2 = "delete from works where id={$id}";
			 $result = $this->conn->query($sql2) or die('删除失败！'.mysql_error());

		}

		function Department(){
			$sql='select * from department';
			$data=$this->conn->query($sql);
			return $data;
		}

		function detail_department($id){
			$sql="select *from employees where did={$id}";
			$data=$this->conn->query($sql);
			return $data;
		}

	}
?>